<?php
//controller untuk pendaftaran
//menampilkan berdasarkan tabel
//menampilkan data berdasarkan filter
//menampilkan data berdasarkan pagination

class c_login extends Controller
{
	function __construct()
	{
		parent:: __construct();
		parent::Controller();
		$this->load->model('m_admin');
		$this->load->helper(array("html","form","url","text"));
		$this->load->library("session");
	}
//
	public function index()
	{	//$config['base_url'] = base_url().'/'.$this->config->item('index_page').'/PUciptakarya/index/';
		$data['msg_login']="";
		//$this->load->view('admin/header');
		$this->load->view('admin/v_login',$data);
		//$this->load->view('pertemuanrohani/portal',$data);
		//$this->load->view('pendaftar/index', $data);
		//$this->load->view('admin/footer');
		
	}
	
	public function home()
	{if(isset($_POST['submit']))
		{
		$data['thnanggaran'] = $this->input->post('thnanggaran');
		$thnanggaran=$data['thnanggaran'];
		$this->session->set_userdata("thnanggaran",$thnanggaran);
		
		$this->load->view('v_home',$data);
		}
	}
	
	public function proseslogin()
	{ 
	 $username = $this->input->post('username');
	 $password = $this->input->post('password');
	 
	 $passwordx = md5($password); 
	 //$username="agus";
	 //$password="agus";
//the query is to matching the username+password user with username+password from database
	
	$q = $this->db->query("SELECT * FROM user WHERE username='$username' AND password='$password' ");
	
	if ($q->num_rows() == 1) 
		{
		
		$data['msg_login']="";
		// if the query is TRUE, then save the username into session and load the welcome view
		$this->session->set_userdata("isLogin",'True');
		$res = $q->row();
		#$this->session->set_userdata("kd_prov",'True');
		#$this->session->set_userdata("kd_kab",'True');
		$this->load->view('admin/v_thnAnggaran',$data);
		
		//$this->load->view('admin/v_kesuksesan', $data);
		//$this->load->view('welcome_view', $data);
		//$this->load->view('pertemuanrohani/portal',$data);
		
		}
	else {
// query error
	//echo "kadieu....";
	$this->session->set_userdata("isLogin",'False');
	$data['msg_login']="Anda belum login dengan benar";
	$this->load->view('admin/v_login',$data);

	
	//$this->load->view('pertemuanrohani/portal', $data);
	}
	}
	
//to do logout process
	public function logout()
	{
	 $this->session->sess_destroy();
	$data['logout'] = 'You have been logged out.';
	$this->load->view('admin/v_login', $data);
	}
}
